/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package NetworkSender;

import java.io.IOException;
import java.io.OutputStream;
import java.util.Queue;
import java.util.concurrent.ArrayBlockingQueue;
import javax.microedition.io.StreamConnection;

/**
 * used to send xml message using a connection
 */
public class NetworkSender {
    static NetworkSender instance;
    Queue<String> queue;
    NetworkSender()
    {
        queue = new ArrayBlockingQueue<String>(100);
    }
    public static NetworkSender getInstance()
    {
        if(instance == null)
        {
            instance = new NetworkSender();
        }
        return instance;
    }
    public boolean isReady()
    {
        if(queue.size() >= 100)
            return false;
        return true;
    }
    public void addItem(String msg)
    {
        if(isReady())
            queue.add(msg);
    }
    public void sendXMLItem(StreamConnection strConn,String xml)        // send the message
    {
        try
        {
            OutputStream out = strConn.openOutputStream();
            out.write(xml.getBytes());
        }catch(IOException ioex)
        {

        }
    
    }
}